package atm;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

/**
 * 查询
 */
public class SearchPanel extends JPanel implements ActionListener {
    private AtmGUI atmGUI;
    private JLabel moneyLabel = new JLabel("您的金额为：");
    private JLabel blanceLabel = new JLabel();
    private Font font = new Font("宋体",Font.BOLD,18);
    private JButton sureBtn = new JButton(new ImageIcon("images\\buttonSure.jpg"));
    private JButton offBtn = new JButton(new ImageIcon("images\\buttonOff.jpg"));
    public SearchPanel(AtmGUI atmGUI){
        this.atmGUI = atmGUI;
        this.setLayout(null);
        this.setOpaque(false);
        moneyLabel.setBounds(300,200,200,50);
        moneyLabel.setFont(font);
        this.add(moneyLabel);
        blanceLabel.setBounds(450,200,250,50);
        blanceLabel.setFont(font);
        this.add(blanceLabel);
        sureBtn.setBounds(800,400,140,50);
        sureBtn.addActionListener(this);
        this.add(sureBtn);
        offBtn.setBounds(0,400,140,50);
        offBtn.addActionListener(this);
        this.add(offBtn);
    }
    public void showBlance(){

    }
    @Override
    public void actionPerformed(ActionEvent e) {
        ArrayList<User> users = atmGUI.getUsers();
        int  index = atmGUI.index;
        if (e.getSource() == offBtn){
            blanceLabel.setText("");
            atmGUI.showPanel("menu");
        }else if (e.getSource() == sureBtn){
            blanceLabel.setText(users.get(index).getBlance() + "");
        }


    }
}
